


const app = getApp();


Page({

  data: {
    loadingHide: false,  //false显示加载中
    availAmount: "0.00", //余额
    withdrawAmount: "",
  },
  onLoad: function () {


    //初始化
    this.getReLoad();

    
  },
  getReLoad: function(){
    var that = this;
    
    //重新加载某些部件
    //获取账户余额
    that.getAccount();
    
    
   
  },
  //获取账户金额
  getAccount: function () {
    var that = this;
    var url = app.data.url + "/account.do";
    var dataForm = {
      'userId': app.data.userid
    };
    app.sendPost(url, dataForm, function (res) {
      console.log(res);
      that.setData({
        loadingHide: true
      });
      that.setData({
        availAmount: res.data.availAmount
      });
    });
  },
  onPullDownRefresh: function () {
    this.getBonusActivityList();
    //隐藏下拉框
    wx.stopPullDownRefresh();

  },
  //金额
  amountInput: function (e) {
    this.setData({
      amount: e.detail.value
    });
  },
  //远程调用发起提现申请
  withdraw: function(){
    var that = this;
    that.setData({
      loadingHide: false
    });
    var url = app.data.url + "/widthdraw.do";
    var dataForm = {
      'userId': app.data.userid,
      'withdrawFee': that.data.amount * 100
    };
    app.sendPost(url, dataForm, function (res) {
      that.setData({
        loadingHide: true
      });
      console.log(res);
      //判断业务逻辑
      if(res){
        if(res.result == "100"){
          that.getReLoad();
          wx.showModal({
            title: '提示',
            content: '提现申请中',
            success: function (res) {
              if (res.confirm) {
                //用户点击确认

              } else if (res.cancel) {
                
              }
            }
          });
        } else if (res.result == "902"){
          wx.showModal({
            title: '提示',
            content: res.message,
            success: function (res) {
              if (res.confirm) {
                //用户点击确认

              } else if (res.cancel) {
                
              }
            }
          });
        }
      }
    });

  },
  //全部提现
  allWithdraw: function(){
    this.data.withdrawAmount = this.data.availAmount;
    this.setData({
      withdrawAmount: this.data.withdrawAmount,
      amount: this.data.withdrawAmount
    });
  }

})